package main

import "fmt"

func fibLoop(n int) int {

	switch {

	case n < 0:
		panic("n is negative")
	case n == 0:
		return 0
	case n == 1 || n == 2:
		return 1
	}
	a, b := 1, 1
	for i := 0; i < n-2; i++ {
		a, b = b, a+b
	}
	return b
}

//1.递推公式
// func fib1(n int) int {
// 	t := fib1(n-1) + fib1(n-2)
// 	return t

// }

func fib1(n int) int {

	if n == 1 || n == 2 {
		return 1
	} else if n < 0 {
		panic("n is negative")
	} else if n == 0 {
		return 0
	}

	return fib1(n-1) + fib1(n-2)
}

func main() {
	for i := 0; i < 15; i++ {
		fmt.Println(i, fibLoop(i), fib1(i))
	}
}
